home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
203_01
/
yam2.c
< prev
next >
Wrap
Text File
|
1980-01-01
|
17KB
|
732 lines
/*
$title ('yam2.c: file transmission protocol handlers')
$date (4 nov 85)
*/
/*
* Ward Christensen Protocol handler for sending and receiving
* ascii and binary files. Modified for choice of checksum or crc.
*/
#include "yam.h"
#define WCEOT (-10)
#ifdef DEFBYTL
long Modtime; /* Unix style mod time for incoming file */
int Filemode; /* Unix style mode for incoming file */
#endif
/****************************************************************************
FUNCTION:
Ward Christensen modem 7 protocol file tranmission handler
CALLING PARAMETERS:
argc:
count of command line arguments.
argp:
pointer to string of command line arguments.
===========================================================================*/
wcsend(argc, argp)
char **argp;
{
int wcs();
#ifdef IBMPC
/* enbable raw mode */
enblcm(FALSE);
#endif
Crcflg=FALSE;
firstsec=TRUE;
if (Batch)
{
printf("Sending in Batch Mode\n");
/* send files, batch mode */
if (expand(wcs, argc, argp)==ERROR)
goto fubar;
/* transmit null path name for end of data */
if (wctxpn("")==ERROR)
goto fubar;
}
/* send file, not batch mode */
else
{
for (; --argc>=0;)
{
/* open file to transmit. open will compute file size */
if (opentx(1,NULL,*argp++)==ERROR)
goto fubar;
/* Ward Christensen transmit */
if (wctx()==ERROR)
goto fubar;
}
}
return OK;
/* error, close files and send CAN to other end */
fubar:
closetx(TRUE);
canit();
return ERROR;
} /* wcsend */
/****************************************************************************
FUNCTION:
Ward Christensen modem 7 protocol file transmission handler, batch
mode.
CALLING PARAMETERS:
f_buf:
pointer to a structure containing information about file
*pathname:
pointer to directory path name
===========================================================================*/
wcs(f_buf,pathname)
struct find_buf *f_buf;
char *pathname;
{
/* open file, open uses f_buf for file size */
if (opentx(2,f_buf,pathname)==ERROR)
return OK; /* skip over inaccessible files */
if (wctxpn(f_buf->pname)== ERROR)
return ERROR;
if (wctx()==ERROR)
return ERROR;
printf("\n");
return OK;
} /* wcs */
/****************************************************************************
FUNCTION:
Ward Christensen modem 7 protocol file reception handler
CALLING PARAMETERS:
argc:
count of command line arguments.
argp:
pointer to string of command line arguments.
===========================================================================*/
wcreceive(argc, argp)
char **argp;
{
int baslen;
#ifdef IBMPC
/* enbable raw mode */
enblcm(FALSE);
#endif
if (Batch)
{
printf("Receiving in Batch Mode\n");
for (;;)
{
/* create the basename of pathname if one was specified */
if (argc > 0)
{
strcpy(Utility.ubuf,*argp);
baslen=strlen(Utility.ubuf);
}
else
baslen = 0;
/* get file name for batch mode */
if (wcrxpn(&Utility.ubuf[baslen])== ERROR)
goto fubar;
if (Utility.ubuf[baslen]==0)
return OK;
#ifdef DEFBYTL
procheader(Utility.ubuf);
#endif
/* receive file */
if (wcrx(Utility.ubuf)==ERROR)
goto fubar;
}
}
else
for (; --argc>=0;)
{
#ifdef DEFBYTL
procheader(0);
#endif
#ifdef XMODEM
printf("Receive:'%s' FILE OPEN\n", *argp);
#endif
if (wcrx(*argp++)==ERROR)
goto fubar;
}
return OK;
fubar:
canit();
closerx(TRUE);
return ERROR;
} /* wcreceive */
/****************************************************************************
FUNCTION:
Fetch a pathname from the other end as a C ctyle ASCII string.
Length is indeterminate as long as less than blklen
a null string represents no more files
CALLING PARAMETERS:
===========================================================================*/
wcrxpn(rpn)
char *rpn; /* receive a pathname */
{
purgeline();
firstsec=TRUE;
#ifdef STATLINE
lpstat("Fetching pathname");
#else
printf("\nFetching pathname ");
#endif
/* slight pause to allow slow systems to get ready */
sleep(5);
totsecs = -1;
if (wcgetsec(rpn, 100, Crcflg?WANTCRC:NAK) != 0)
return ERROR;
sendbyte(ACK);
/* clear line of status message above */
#ifndef STATLINE
printf("\r \r");
#endif
return OK;
} /* wcrxpn */
/****************************************************************************
FUNCTION:
transmit path name for batch mode transmission.
CALLING PARAMETERS:
name:
pointer to file name to transmit.
===========================================================================*/
wctxpn(name)
char *name;
{
char *p;
/*??????*/
totsecs = -1;
#ifdef STATLINE
pstat("Awaiting pathname NAK");
#else
printf("Awaiting pathname NAK ");
#endif
if ((firstch=readbyte(400))==TIMEOUT)
return ERROR;
if (firstch==WANTCRC)
Crcflg=TRUE;
/* don't send drive specification */
if (p=index(':', name))
name = ++p;
/* sector number 0 for pathname */
if (wcputsec(name, 0, SECSIZ)==ERROR)
{
printf("Can't send pathname %s\n", name);
return ERROR;
}
#ifndef STATLINE
printf("\r \r");
#endif
return OK;
} /* wctxpn */
/****************************************************************************
FUNCTION:
Adapted from CMODEM13.C, written by Jack M. Wierda and Roderick W. Hart
CALLING PARAMETERS:
===========================================================================*/
wcrx(name)
char *name;
{
int sendchar, sectnum, sectcurr;
#ifdef DEFBYTL
int cblklen; /* bytes to dump this block */
#endif
if (openrx(name)==ERROR)
return ERROR;
firstsec=TRUE;
totsecs=sectnum=0;
sendchar=Crcflg?WANTCRC:NAK;
for (;;)
{
#ifdef STATLINE
if (!Quiet)
pstat("block %3d %2dk", totsecs, totsecs/8 );
#else
if (!Quiet && !View)
printf("\rblock %3d %2dk ", totsecs, totsecs/8 );
#endif
purgeline();
sectcurr=wcgetsec(Utility.ubuf, (sectnum&0177)?70:130,
sendchar);
if (sectcurr==(sectnum+1 &0xff))
{
sectnum++;
/*
* if the compiler supports longs && the o/s blocks the
* exact length of files then and only then use the file length
* info (if transmitted).
*/
#ifdef DEFBYTL
#ifdef BYTEFLENGTH
wcj = cblklen = Bytesleft>blklen ? blklen:Bytesleft;
#else
wcj = cblklen = blklen;
#endif
#else
wcj = blklen;
#endif
for (cp=Utility.ubuf; --wcj>=0; )
if (fputc(*cp++, fout)==ERROR)
{
printf("\nDisk Full\n");
return ERROR;
}
#ifndef XMODEM
if (View)
{
#ifdef DEFBYTL
wcj = cblklen;
#else
wcj = blklen;
#endif
for (cp=Utility.ubuf;--wcj>=0;)
putchar(*cp++);
}
#endif
#ifdef DEFBYTL
if ((Bytesleft -= cblklen) < 0)
Bytesleft = 0;
#endif
totsecs += blklen/128;
sendchar=ACK;
}
else if (sectcurr==sectnum)
{
wcperr("received dup block\n");
sendchar=ACK;
}
else if (sectcurr==WCEOT)
{
sendbyte(ACK);
/* don't pad the file any more than it already is */
closerx(FALSE);
return OK;
}
else if (sectcurr==ERROR)
return ERROR;
else
{
printf(" Sync Error: got %d\n", sectcurr);
return ERROR;
}
}
} /* wcrx */
/****************************************************************************
FUNCTION:
wcgetsec fetches a Ward Christensen type sector.
Returns sector number encountered or ERROR if valid sector not received,
or CAN CAN received or WCEOT if eot sector.
time is timeout for first char, set to 4 seconds thereafter
*************** NO ACK IS SENT IF SECTOR IS RECEIVED OK **************
(Caller must do that when he is good and ready to get next sector)
CALLING PARAMETERS:
rxbuf:
pointer to buffer to place received data from modem
time:
sendchar:
===========================================================================*/
wcgetsec(rxbuf, time, sendchar)
char *rxbuf;
int time;
{
int sectcurr;
for (Lastrx=errors=0; errors<RETRYMAX; ++errors, ++toterrs)
{
/*